package com.situ.gym.controller;

import com.situ.gym.pojo.vo.ChartCountVO;
import com.situ.gym.pojo.vo.CoachCount;
import com.situ.gym.pojo.vo.DayCountVO;
import com.situ.gym.service.ICoachService;
import com.situ.gym.service.ICourseService;
import com.situ.gym.service.IReserveService;
import com.situ.gym.service.IUserService;
import com.situ.gym.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/chart")
//RequestMapping URL 路径映射：将  HTTP 请求路径 /chart 映射到 ChartController 类中的所有处理方法（Handler Methods）。
//类级别注解：@RequestMapping 标注在类上时，定义该控制器下所有方法的公共路径前缀。
public class ChartController {
    @Autowired
    private ICoachService coachService;
    @Autowired
    private ICourseService courseService;
    @Autowired
    private IUserService userService;
    @Autowired
    private IReserveService reserveService;

    //统计图表的教练的课程数(按教练划分课程)
    @GetMapping("/selectCoachCount")
    public Result<List<CoachCount>> selectCoachCount() {
       List<CoachCount> list = coachService.selectCoachCount();
       return Result.ok(list);
    }
    //统计图表的热门top10课程数(按人数（user）划分课程并排序)
    @GetMapping("/selectHotCourse")
    public Result<List<ChartCountVO>> selectHotCourse() {
        List<ChartCountVO> list = courseService.selectHotCourse();
        return Result.ok(list);
    }
    //统计以下四种数据总数（qw）
    @GetMapping("/selectUserTotal")
    public Result<Long> selectUserTotal() {
        long count = userService.count();
        return Result.ok(count);
    }

    @GetMapping("/selectCoachTotal")
    public Result<Long> selectCoachTotal() {
        long count = coachService.count();
        return Result.ok(count);
    }

    @GetMapping("/selectReserveTotal")
    public Result<Long> selectReserveTotal() {
        long count = reserveService.count();
        return Result.ok(count);
    }

    @GetMapping("/selectCourseTotal")
    public Result<Long> selectCourseTotal() {
        long count = courseService.count();
        return Result.ok(count);
    }

    //统计用户user变化趋势
    @GetMapping("/selectUserCount")
    public Result<List<DayCountVO>> selectUserCount(Date date) {
        List<DayCountVO> list = userService.selectUserCount(date);
        return Result.ok(list);
    }
    //统计用户预约Reserve变化趋势
    @GetMapping("/selectReserveCount")
    public Result<List<DayCountVO>> selectReserveCount(Date date) {
        List<DayCountVO> list = reserveService.selectReserveCount(date);
        return Result.ok(list);
    }
}
